package com.liurong.netty.v2.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

public class ChatServerInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		// 信道管道
		ChannelPipeline pipeline = ch.pipeline();
		// pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
		// Delimiters.lineDelimiter()));

		// pipeline.addLast("log", new LoggingHandler(LogLevel.INFO));
		// 编码
		pipeline.addLast("decoder", new StringDecoder());
		// 解码
		pipeline.addLast("encoder", new StringEncoder());

		pipeline.addLast("http", new HttpClientCodec());

		// 消息处理器
		pipeline.addLast("chat", new ChatServerHandler());

		// 心跳
		// pipeline.addLast("heartbeat", new IdleStateHandler(1, 1, 1,
		// TimeUnit.SECONDS));
	}
}
